package com.ysq.www.common.utils.task;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.ysq.www.api.user.entity.WxConfig;
import com.ysq.www.api.user.service.IWxConfigService;
import com.ysq.www.common.utils.message.HttpClientUtils;
import com.ysq.www.common.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Slf4j
@Component
public class TokenTask {

    @Autowired
    private IWxConfigService wxConfigService;

    @Autowired
    private RedisUtil redisUtil;

    /*@Scheduled(cron = "0 0 0/2 * * ?")
    public void getAccessToken(){
        WxConfig wx = wxConfigService.getById(1);
        try {
            JSONObject js = HttpClientUtils.getAccessToken(wx.getAppId(), wx.getAppSecret());
            String accessToken = js.getString("access_token");
            if (StringUtils.isEmpty(accessToken)){
                int errCode = js.getIntValue("errcode");
                log.info("获取小程序全局Token失败，错误码:"+errCode);
            }
            redisUtil.set("accessToken",accessToken);
        } catch (IOException e) {
            log.error("获取access_token失败!");
            e.printStackTrace();
            return;
        }
    }*/


}
